package com.zhicheng.mapper;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhicheng.pojo.*;
import com.zhicheng.pojo.dto.GoodDTO;
import com.zhicheng.pojo.vo.GoodVO;
import com.zhicheng.pojo.vo.PicturesVO;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface GoodMapper {

    @Select("select * from goods where id = #{id}")
    GoodVO getGoodsById(Long id);

    @Select("select img_url from pictures where good_id = #{id};")
    List<String> getPicturesByGoodId(Long id);

    @Select("select * from goods where parent_id = #{parentId} order by likeCount desc limit #{limit}")
    List<GoodVO> getHotGoodsByLikeCount(Long parentId,Long limit);

    @Select("select * from goods where seller_id = #{userId}")
    List<Good> getByUserId(Long userId);

    List<Good> list(Long userId, Integer categoryId, Integer status);

    @Insert("insert into goods (parent_id, parent_name, category_id, category_name, seller_id, name, price, `desc`, picture, likeCount, collectCount, commentCount, status, create_time, update_time) " +
            "values (#{parentId},#{parentName},#{categoryId},#{categoryName},#{sellerId},#{name},#{price},#{desc},#{picture},#{likeCount},#{collectCount},#{commentCount},#{status},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") // 告诉 MyBatis 使用自增的 ID
    Long add(Good good);

    @Insert("insert into pictures (good_id, img_url, create_time, update_time) " +
            "VALUES (#{goodId},#{imgUrl},#{createTime},#{updateTime})")
    void addPictures(Pictures pictures);

    void updateGoods(GoodDTO goodDTO);

    @Delete("delete from goods where id = #{id};")
    void deleteGoods(Long id);

    @Delete("delete from pictures where good_id = #{goodId};")
    void deletePictures(Long goodId);
}
